package com.road.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {
	
    private static Properties properties = new Properties();  
    private static String CONFIG = "/jdbc.properties";  
    private static InputStream is = PropertiesUtil.class.getResourceAsStream(CONFIG);  
    public static String JDBC_DRIVER;  
    public static String JDBC_URL;  
    public static String JDBC_USER;  
    public static String JDBC_PASS;  
    
    
	/**
	 * 初始连接池大小
	 */
    public static  int JDBC_INITIALSIZE=10;
	
	/**
	 * 最小空闲连接数
	 */
    public static int JDBC_MINIDLE=2;
	
	/**
	 * 最大活跃连接数
	 */
    public static int JDBC_MAXACTIVE=20;
    
    /**
	 * 数据库类型
	 */
    
    
    
    
    
    
    /**
	 * mail 配置：邮件服务器地址
	 */
	public static final String config_mail_host = "config.mail.host";

	/**
	 * mail 配置：邮件服务器端口
	 */
	public static final String config_mail_port = "config.mail.port";

	/**
	 * mail 配置：邮件服务器账号
	 */
	public static final String config_mail_from = "config.mail.from";

	/**
	 * mail 配置：邮件服务器名称
	 */
	public static final String config_mail_userName = "config.mail.userName";

	/**
	 * mail 配置：邮件服务器密码
	 */
	public static final String config_mail_password = "config.mail.password";

	/**
	 * mail 配置：接收邮件地址
	 */
	public static final String config_mail_to = "config.mail.to";

	/**
	 *  缓存类型配置
	 */
	public static final String config_cache_type = "config.cache.type";

	/**
	 *  redis 配置：数量
	 */
	public static final String config_redis_count = "redis.count";
    
    
    public static String type="mysql";
    static {  
        try {  
            properties.load(is);  
            JDBC_DRIVER = properties.getProperty("jdbc.driver");  
            JDBC_URL = properties.getProperty("jdbc.url");  
            JDBC_USER = properties.getProperty("jdbc.user");  
            JDBC_PASS = properties.getProperty("jdbc.pass"); 
            
            JDBC_INITIALSIZE =Integer.parseInt(properties.getProperty("jdbc.initialSize")) ; 
            JDBC_MINIDLE = Integer.parseInt(properties.getProperty("jdbc.minIdle"));
            JDBC_MAXACTIVE = Integer.parseInt(properties.getProperty("jdbc.maxactive"));
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
    
    public static final String getValBykey(String key) {
    	if(properties==null) {
    		synchronized (PropertiesUtil.class) {
    			return properties.getProperty(key);
			}
    	}else {
    		return properties.getProperty(key);
    	}
	
    }

}
